<template>
  <div class="category-container glass-container">
    <div class="category-header">
      <el-select
          v-model="fenlei1Id"
          placeholder="请选择一级分类"
          size="large"
          class="category-select"
          @change="getFenlei2"
      >
        <el-option
            v-for="item in fenlei1"
            :key="item.name"
            :label="item.name"
            :value="item.id"
        />
      </el-select>

      <el-select
          v-model="fenlei2Id"
          placeholder="请选择二级分类"
          size="large"
          class="category-select"
          @change="getFenlei3"
      >
        <el-option
            v-for="item in fenlei2"
            :key="item.name"
            :label="item.name"
            :value="item.id"
        />
      </el-select>
    </div>

    <div class="products-grid">
      <el-card 
        v-for="item in fenlei3" 
        :key="item.id" 
        class="product-card hover-float"
      >
        <div class="product-content">
          <el-image 
            class="product-image" 
            :src="item.photo" 
            fit="cover" 
            :preview-src-list="[item.photo]"
          />
          <h3 class="product-name gradient-text">{{item.name}}</h3>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import {ref} from "vue";
import {getfenlei1, getfenlei2, getfenlei3} from "@/assets/fenlei.js";
const fenlei1Id=ref()
const fenlei2Id=ref()
const fenlei1=ref()
function getFenlei1(){
  getfenlei1().then(res=>{
    fenlei1.value=res.data
  })
}
getFenlei1()
const fenlei2=ref([])
function getFenlei2(){
  getfenlei2(fenlei1Id.value).then(res=>{
    fenlei2.value=res.data
  })
  fenlei2Id.value=""
  fenlei3.value=null
}
const fenlei3=ref([])
function getFenlei3(){
  getfenlei3(fenlei2Id.value).then(res=>{
    fenlei3.value=res.data
  })
}
</script>

<style scoped>
.category-container {
  min-height: 100vh;
  padding: 24px;
  background: var(--secondary-gradient);
}

.category-header {
  display: flex;
  gap: 20px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.category-select {
  min-width: 240px;
  backdrop-filter: blur(10px);
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  padding: 20px 0;
}

.product-card {
  border: none;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.product-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.product-image {
  width: 100%;
  height: 280px;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.product-image :deep(img) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.product-card:hover .product-image :deep(img) {
  transform: scale(1.05);
}

.product-name {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  margin: 0;
  padding: 0 16px;
  line-height: 1.4;
}

/* Element Plus 组件样式优化 */
:deep(.el-select) {
  width: 100%;
}

:deep(.el-select .el-input__wrapper) {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

:deep(.el-select:hover .el-input__wrapper) {
  box-shadow: var(--shadow-md);
}

:deep(.el-card__body) {
  padding: 16px;
}

/* 响应式设计 */
@media screen and (max-width: 768px) {
  .category-container {
    padding: 16px;
  }

  .category-header {
    gap: 12px;
    margin-bottom: 20px;
  }

  .category-select {
    min-width: 100%;
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    padding: 12px 0;
  }

  .product-image {
    height: 160px;
  }

  .product-name {
    font-size: 14px;
  }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
  .product-card {
    background: rgba(30, 32, 35, 0.95);
  }

  :deep(.el-select .el-input__wrapper) {
    background: rgba(30, 32, 35, 0.9);
  }
}
</style>